<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="充值日期">
        <el-date-picker
          v-model="daterangeInvestTime"
          style="width: 240px"
          value-format="yyyy-MM-dd HH:mm:ss"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          :default-time="['00:00:00', '23:59:59']"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="到账日期">
        <el-date-picker
          v-model="daterangeAccountTime"
          style="width: 240px"
          value-format="yyyy-MM-dd HH:mm:ss"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          :default-time="['00:00:00', '23:59:59']"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="预付垫款" prop="advanceType">
        <el-select v-model="queryParams.advanceType" placeholder="请选择预付垫款" clearable>
          <el-option
            v-for="dict in dict.type.advance_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="方式" prop="type">
        <el-select v-model="queryParams.type" placeholder="请选择方式" clearable>
          <el-option
            v-for="dict in dict.type.way"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="合作方式" prop="operationType">
        <el-select v-model="queryParams.operationType" placeholder="请选择合作方式" clearable>
          <el-option
            v-for="dict in dict.type.cooperate_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="合作媒体" prop="medium">
        <el-input
          v-model="queryParams.medium"
          placeholder="请输入合作媒体"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="账户ID" prop="accountId">
        <el-input
          v-model="queryParams.accountId"
          placeholder="请输入账户ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="帐户名称" prop="accountName">
        <el-input
          v-model="queryParams.accountName"
          placeholder="请输入帐户名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="竞价类别" prop="bidding">
        <el-input
          v-model="queryParams.bidding"
          placeholder="请输入竞价类别"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="客户简称" prop="htName">
        <el-input
          v-model="queryParams.htName"
          placeholder="请输入客户简称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="状态" prop="checkType">
        <el-select v-model="queryParams.checkType" placeholder="请选择状态" clearable>
          <el-option
            v-for="dict in dict.type.finance"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="财务台账状态" prop="financeType">
        <el-select v-model="queryParams.financeType" placeholder="请选择财务台账状态" clearable>
          <el-option
            v-for="dict in dict.type.finance"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['bill:customInvest:add']"
        >新增</el-button>
      </el-col>
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="success"-->
<!--          plain-->
<!--          icon="el-icon-edit"-->
<!--          size="mini"-->
<!--          :disabled="single"-->
<!--          @click="handleUpdate"-->
<!--          v-hasPermi="['bill:customInvest:edit']"-->
<!--        >修改</el-button>-->
<!--      </el-col>-->
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['bill:customInvest:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="info"
          plain
          icon="el-icon-upload2"
          size="mini"
          @click="handleImport"
        >导入</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['bill:customInvest:export']"
        >导出</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleRecord"
          v-hasPermi="['bill:customInvest:add']"
        >补录</el-button>
      </el-col>
      <el-col :span="1.5" style="color: gray">
        广告币合计: {{currCus}}
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="customInvestList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="充值日期" align="center" prop="investTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.investTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="到账日期" align="center" prop="accountTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.accountTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="客户简称" align="center" prop="htName" />
      <el-table-column label="主合同" align="center" prop="mainParty" />
      <el-table-column label="预付垫款" align="center" prop="advanceType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.advance_type" :value="scope.row.advanceType"/>
        </template>
      </el-table-column>
      <el-table-column label="付款方式" align="center" prop="payType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.pay_type" :value="scope.row.payType"/>
        </template>
      </el-table-column>
      <el-table-column label="合作方式" align="center" prop="cooperateType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.cooperate_type" :value="scope.row.cooperateType"/>
        </template>
      </el-table-column>
      <el-table-column label="合作媒体" align="center" prop="medium">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.medium" :value="scope.row.medium"/>
        </template>
      </el-table-column>
      <el-table-column label="账户ID" align="center" prop="accountId" />
      <el-table-column label="账户名称" align="center" prop="accountName" />
      <el-table-column label="竞价类别" align="center" prop="bidding" />
      <el-table-column label="充值广告币" align="center" prop="currency" />
      <el-table-column label="账显返点" align="center" prop="rate" />
      <el-table-column label="应收现金" align="center" prop="inCash" />
      <el-table-column label="实收现金" align="center" prop="actualCash" />
      <el-table-column label="剩余备款" align="center" prop="balance" />
<!--      <el-table-column label="到账截图" align="center" prop="image" width="100">-->
<!--        <template slot-scope="scope">-->
<!--          <image-preview :src="scope.row.image" :width="50" :height="50"/>-->
<!--        </template>-->
<!--      </el-table-column>-->
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="状态" align="center" prop="checkType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.finance" :value="scope.row.checkType"/>
        </template>
      </el-table-column>
      <el-table-column label="财务匹配状态" align="center" prop="financeType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.finance" :value="scope.row.financeType"/>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="90px" fixed="right" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            type="text"
            icon="el-icon-edit"
            size="mini"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['bill:customInvest:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['bill:customInvest:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改客户台账对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1000px" append-to-body>

      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-row>
          <el-col :span="8">
            <el-form-item label="充值日期" prop="investTime">
              <el-date-picker style="width: 100%" clearable
                              v-model="form.investTime"
                              type="date"
                              value-format="yyyy-MM-dd HH:mm:ss"
                              placeholder="请选择充值日期">
              </el-date-picker>
            </el-form-item>
          </el-col>

          <el-col :span="8">
            <el-form-item label="到账日期" prop="accountTime">
              <el-date-picker style="width: 100%" clearable
                              v-model="form.accountTime"
                              type="date"
                              value-format="yyyy-MM-dd HH:mm:ss"
                              placeholder="请选择到账日期">
              </el-date-picker>
            </el-form-item>
          </el-col>

          <el-col :span="8">
            <el-form-item label="客户简称" prop="htName">
              <el-input v-model="form.htName" placeholder="请输入客户简称" disabled/>
            </el-form-item>

          </el-col>
        </el-row>


        <el-row>


          <el-col :span="8">
            <el-form-item label="预付垫款" prop="advanceType">
              <el-select style="width: 100%" v-model="form.advanceType" placeholder="请选择预付垫款">
                <el-option
                  v-for="dict in dict.type.advance_type"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="账户ID" prop="accountId">
              <el-input v-model="form.accountId" placeholder="请输入账户ID" @change="accountIdChange" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="合作媒体" prop="medium">
              <el-select style="width: 100%" v-model="form.medium" placeholder="请选择合作媒体" disabled>
                <el-option
                  v-for="dict in dict.type.medium"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>



          <el-col :span="8">
            <el-form-item label="账户名称" prop="accountName">
              <el-input v-model="form.accountName" placeholder="请输入账户名称" disabled/>
            </el-form-item>
          </el-col>

          <el-col :span="8">
            <el-form-item label="竞价类别" prop="bidding">
              <el-input v-model="form.bidding" placeholder="请输入竞价类别" disabled/>
            </el-form-item>
          </el-col>

          <el-col :span="8">
            <el-form-item label="主合同" prop="mainParty">
              <el-input v-model="form.mainParty" placeholder="请输入主合同" disabled/>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>


          <el-col :span="8">
            <el-form-item label="合作方式" prop="cooperateType">
              <el-select style="width: 100%" v-model="form.cooperateType" placeholder="请选择合作方式"  @change="pcChange" >
                <el-option
                  v-for="dict in dict.type.cooperate_type"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="付款方式" prop="payType">
              <el-select style="width: 100%" v-model="form.payType" placeholder="请选择付款方式"  @change="pcChange" >
                <el-option
                  v-for="dict in dict.type.pay_type"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="8">
            <el-form-item label="账显返点" prop="rate">

              <el-select style="width: 100%" v-model="form.rate" @change="rateCount" placeholder="请选择账显返点">
                <el-option
                  v-for="point in pointList"
                  :key="point.id"
                  :label="point.accountPoint"
                  :value="point.accountPoint"
                >
                  <template slot="append">%</template>
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>


          <el-col :span="8">
            <el-form-item label-width	="auto" label="充值广告币" prop="currency">
              <el-input style="width: 65%" v-model="form.currency"  @change="currencyCount" placeholder="请输入充值广告币" />
            </el-form-item>
          </el-col>

          <el-col :span="8">
            <el-form-item label="应收现金" prop="inCash">
              <el-input v-model="form.inCash" placeholder="请输入应收现金" :disabled="form.advanceType!='退现'"/>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="8">
            <el-form-item label="实收现金" prop="actualCash">
              <el-input v-model="form.actualCash" placeholder="请输入实收现金" />
            </el-form-item>
          </el-col>

          <el-col :span="8">
            <el-form-item label="剩余备款" prop="balance">
              <el-input v-model="form.balance" placeholder="请输入剩余备款" disabled/>
            </el-form-item>
          </el-col>

        </el-row>

<!--        <el-row>-->
<!--          <el-col :span="24">-->
<!--            <el-form-item label="到账截图" prop="image">-->
<!--              <image-upload v-model="form.image"/>-->
<!--            </el-form-item>-->
<!--          </el-col>-->
<!--        </el-row>-->

        <el-row>
          <el-col :span="24">
            <el-form-item label="备注" prop="remark">
              <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
            </el-form-item>
          </el-col>
        </el-row>


      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 导入对话框 -->
    <el-dialog :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
      <el-upload
        ref="upload"
        :limit="1"
        accept=".xlsx, .xls"
        :headers="upload.headers"
        :action="upload.url + '?updateSupport=' + upload.updateSupport"
        :disabled="upload.isUploading"
        :on-progress="handleFileUploadProgress"
        :on-success="handleFileSuccess"
        :auto-upload="false"
        drag
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <div class="el-upload__tip text-center" slot="tip">

          <span>仅允许导入xls、xlsx格式文件。</span>
          <el-link type="primary" :underline="false" style="font-size:12px;vertical-align: baseline;" @click="importTemplate">下载模板</el-link>
        </div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">确 定</el-button>
        <el-button @click="upload.open = false">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 补录对话框 -->
    <el-dialog :title="title" :visible.sync="openRecord" width="1000px" append-to-body>

      <div slot="footer" class="dialog-footer">
        <el-button :loading="buttonLoading" type="primary" @click="submitRecordForm">确 定</el-button>
        <el-button @click="cancelRecord">取 消</el-button>
      </div>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-row>
          <el-col :span="8">
            <el-form-item label="充值日期" prop="investTime">
              <el-date-picker style="width: 100%" clearable
                              v-model="form.investTime"
                              type="date"
                              value-format="yyyy-MM-dd HH:mm:ss"
                              placeholder="请选择充值日期">
              </el-date-picker>
            </el-form-item>
          </el-col>

          <el-col :span="8">
            <el-form-item label="到账日期" prop="accountTime">
              <el-date-picker style="width: 100%" clearable
                              v-model="form.accountTime"
                              type="date"
                              value-format="yyyy-MM-dd HH:mm:ss"
                              placeholder="请选择到账日期">
              </el-date-picker>
            </el-form-item>
          </el-col>

          <el-col :span="8">
            <el-form-item label="客户简称" prop="htName">
              <el-input v-model="form.htName" placeholder="请输入客户简称" disabled/>
            </el-form-item>

          </el-col>
        </el-row>


        <el-row>


          <el-col :span="8">
            <el-form-item label="预付垫款" prop="advanceType">
              <el-select style="width: 100%" v-model="form.advanceType" placeholder="请选择预付垫款">
                <el-option
                  v-for="dict in dict.type.advance_type"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="账户ID" prop="accountId">
              <el-input v-model="form.accountId" placeholder="请输入账户ID" @change="accountIdChange" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="合作媒体" prop="medium">
              <el-select style="width: 100%" v-model="form.medium" placeholder="请选择合作媒体" disabled>
                <el-option
                  v-for="dict in dict.type.medium"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>

        </el-row>

        <el-row>

          <el-col :span="8">
            <el-form-item label="账户名称" prop="accountName">
              <el-input v-model="form.accountName" placeholder="请输入账户名称" disabled/>
            </el-form-item>
          </el-col>

          <el-col :span="8">
            <el-form-item label="竞价类别" prop="bidding">
              <el-input v-model="form.bidding" placeholder="请输入竞价类别" disabled/>
            </el-form-item>
          </el-col>

          <el-col :span="8">
            <el-form-item label="主合同" prop="mainParty">
              <el-input v-model="form.mainParty" placeholder="请输入主合同" disabled/>
            </el-form-item>
          </el-col>


        </el-row>

        <el-row>
          <el-col :span="8">
            <el-form-item label="合作方式" prop="cooperateType">
              <el-select style="width: 100%" v-model="form.cooperateType" placeholder="请选择合作方式"  @change="pcChange" >
                <el-option
                  v-for="dict in dict.type.cooperate_type"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>


          <el-col :span="8">
            <el-form-item label="付款方式" prop="payType">
              <el-select style="width: 100%" v-model="form.payType" placeholder="请选择付款方式"  @change="pcChange" >
                <el-option
                  v-for="dict in dict.type.pay_type"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="8">
            <el-form-item label="账显返点" prop="rate">

              <el-select style="width: 100%" v-model="form.rate" @change="rateCount" placeholder="请选择账显返点">
                <el-option
                  v-for="dict in dict.type.pointList"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                >
                  <template slot="append">%</template>
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

          <el-row>
            <el-col :span="8">
              <el-form-item label-width	="auto" label="充值广告币" prop="currency">
                <el-input style="width: 65%" v-model="form.currency"  @change="currencyCount" placeholder="请输入充值广告币" />
              </el-form-item>
            </el-col>



            <el-col :span="8">
              <el-form-item label="应收现金" prop="inCash">
                <el-input v-model="form.inCash" placeholder="请输入应收现金" :disabled="form.advanceType!='退现'"/>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row>
            <el-col :span="8">
              <el-form-item label="实收现金" prop="actualCash">
                <el-input v-model="form.actualCash" placeholder="请输入实收现金" />
              </el-form-item>
            </el-col>

            <el-col :span="8">
              <el-form-item label="剩余备款" prop="balance">
                <el-input v-model="form.balance" placeholder="请输入剩余备款" disabled/>
              </el-form-item>
            </el-col>

          </el-row>

          <!--        <el-row>-->
          <!--          <el-col :span="24">-->
          <!--            <el-form-item label="到账截图" prop="image">-->
          <!--              <image-upload v-model="form.image"/>-->
          <!--            </el-form-item>-->
          <!--          </el-col>-->
          <!--        </el-row>-->

          <el-row>
            <el-col :span="24">
              <el-form-item label="备注" prop="remark">
                <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
              </el-form-item>
            </el-col>
          </el-row>


      </el-form>
    </el-dialog>

  </div>
</template>

<script>
import { listCustomInvest, getCustomInvest, delCustomInvest, addCustomInvest, updateCustomInvest,record } from "@/api/bill/customInvest";
import { listAccount } from "@/api/baseMain/account";
import { listPolicy} from "@/api/baseMain/policy";
import { getToken } from "@/utils/auth";

export default {
  name: "CustomInvest",
  dicts: ['advance_type', 'way', 'medium', 'operation_type', 'finance', 'pay_type', 'cooperate_type'],
  data() {
    return {
      currCus:0,
      // 未校验备款时间范围
      daterangeInvestTime: [],
      // 未校验备款时间范围
      daterangeAccountTime: [],
      // 导入参数
      upload: {
        // 是否显示弹出层（导入）
        open: false,
        // 弹出层标题（导入）
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的数据
        updateSupport: 0,
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/bill/customInvest/importData"
      },
      // 按钮loading
      buttonLoadingRecord: false,
      buttonLoading: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 客户台账表格数据
      customInvestList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      openRecord: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        htName: undefined,
        accountName: undefined,
      },
      pointList:[],
      // 表单参数
      form: {
        actualCash:0
      },
      // 表单校验
      rules: {
        id: [
          { required: true, message: "主键不能为空", trigger: "blur" }
        ],
        advanceType:[
          { required: true, message: "预付垫款不能为空", trigger: "blur" }
        ],
        investTime:[
          { required: true, message: "充值时间不能为空", trigger: "blur" }
        ],
        accountTime:[
          { required: true, message: "到账时间不能为空", trigger: "blur" }
        ],
        cooperateType:[
          { required: true, message: "合作方式不能为空", trigger: "blur" }
        ],
        payType:[
          { required: true, message: "付款方式不能为空", trigger: "blur" }
        ],
        rate:[
          { required: true, message: "账显返点不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    pcChange(){
      this.form.rate = undefined
     if(this.form.mainParty !=null &&this.form.mainParty !=undefined&& this.form.mainParty !=''){
       listPolicy({
         mainParty: this.form.mainParty,
         signatory:this.form.medium,
         policyType:this.form.bidding,
         cooperateType:this.form.cooperateType,
         payType:this.form.payType
       }).then(res =>{
         this.pointList = res.rows
       })
     }

    },
    /** 导入按钮操作 */
    handleImport() {
      this.upload.title = "数据导入";
      this.upload.open = true;
    },
    /** 下载模板操作 */
    importTemplate() {
      this.download('bill/customInvest/importTemplate', {
      }, `account_template_${new Date().getTime()}.xlsx`)
    },
    // 文件上传中处理
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true;
    },
    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      this.upload.open = false;
      this.upload.isUploading = false;
      this.$refs.upload.clearFiles();
      this.$alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + response.msg + "</div>", "导入结果", { dangerouslyUseHTMLString: true });
      this.getList();
    },
    // 提交上传文件
    submitFileForm() {
      this.$refs.upload.submit();
    },
    rateCount(e){
      this.form.inCash = undefined

      if(e != '' && e != undefined){
        if(this.form.currency != '' && this.form.currency != undefined){
          this.form.inCash = (this.form.currency / (Number(1)+Number(e*0.01))).toFixed(2)
        }
      }
    },
    currencyCount(e){
      this.form.inCash = undefined
      if(e != '' && e != undefined){
        if(this.form.rate != '' && this.form.rate != undefined){
           this.form.inCash = (e / (Number(1)+Number(this.form.rate*0.01))).toFixed(2)
        }
      }
    },
    accountIdChange(e){
      this.form.inCash = undefined
      this.form.htName = undefined
      this.form.medium = undefined
      this.form.mainParty = undefined
      this.form.accountName = undefined
      this.form.bidding = undefined
      this.form.rate = undefined
      this.pointList = []
      //搜索客户政策

      listAccount({accountId:e}).then(response =>{
        if(response.rows.length === 1){
          this.form.medium = response.rows[0].signatory
          this.form.accountName = response.rows[0].accountName
          this.form.mainParty = response.rows[0].mainParty
          this.form.bidding = response.rows[0].bidding
          this.form.htName = response.rows[0].customName
          listPolicy({
            mainParty: this.form.mainParty,
            signatory:this.form.medium,
            policyType:this.form.bidding,
            policyTag:response.rows[0].policyTag
          }).then(res =>{
            console.log(res)
            this.pointList = res.rows
          })
          if(this.form.currency != '' && this.form.currency != undefined){
            this.form.inCash = (this.form.currency / (Number(1)+Number(this.form.rate*0.01))).toFixed(2)
          }
        }else{
          this.form.inCash = undefined
          this.form.htName = undefined
          this.form.medium = undefined
          this.form.mainParty = undefined
          this.form.accountName = undefined
          this.form.bidding = undefined
          this.form.rate = undefined
          this.pointList = []
        }
      })
      this.rateCount()
    },
    /** 查询客户台账列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangeInvestTime && '' != this.daterangeInvestTime) {
        this.queryParams.params["beginInvestTime"] = this.daterangeInvestTime[0];
        this.queryParams.params["endInvestTime"] = this.daterangeInvestTime[1];
      }
      if (null != this.daterangeAccountTime && '' != this.daterangeAccountTime) {
        this.queryParams.params["beginAccountTime"] = this.daterangeAccountTime[0];
        this.queryParams.params["endAccountTime"] = this.daterangeAccountTime[1];
      }
      listCustomInvest(this.queryParams).then(response => {
        this.customInvestList = response.rows;
        this.total = response.total;
        this.currCus = response.currCus !=null? response.currCus.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","):0;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 取消按钮
    cancelRecord() {
      this.openRecord = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        investTime: undefined,
        accountTime: undefined,
        htName: undefined,
        advanceType: undefined,
        type: undefined,
        operationType: undefined,
        medium: undefined,
        accountId: undefined,
        accountName: undefined,
        bidding: undefined,
        currency: undefined,
        rate: undefined,
        inCash: undefined,
        actualCash: 0,
        balance: undefined,
        image: undefined,
        remark: undefined,
        checkType: undefined,
        pnsoi: undefined,
        urif: undefined,
        createTime: undefined,
        createBy: undefined,
        updateTime: undefined,
        cooperateType: undefined,
        payType: undefined,
        updateBy: undefined
      };
      this.resetForm("form");
    },
    handleRecord(){
      this.reset();
      this.openRecord = true;
      this.title = "补录端口台账";
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加客户台账";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.loading = true;
      this.reset();
      const id = row.id || this.ids
      getCustomInvest(id).then(response => {
        this.loading = false;
        this.form = response.data;
        this.open = true;
        this.title = "修改客户台账";
      });
    },
    submitRecordForm(){
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.buttonLoadingRecord = true;
          record(this.form).then(response => {
            this.$modal.msgSuccess("补录成功");
            this.openRecord = false;
            this.getList();
          }).finally(() => {
            this.buttonLoadingRecord = false;
          });
        }
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.buttonLoading = true;
          if (this.form.id != null) {
            updateCustomInvest(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            }).finally(() => {
              this.buttonLoading = false;
            });
          } else {
            addCustomInvest(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            }).finally(() => {
              this.buttonLoading = false;
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      if(this.ids.length>1){
        this.$modal.msgSuccess("暂不支持批量删除");
        return;
      }
      this.$modal.confirm('是否确认删除客户台账编号为"' + ids + '"的数据项？').then(() => {
        this.loading = true;
        return delCustomInvest(ids);
      }).then(() => {
        this.loading = false;
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      }).finally(() => {
        this.loading = false;
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('bill/customInvest/export', {
        ...this.queryParams
      }, `customInvest_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
